package cn.com.woxitech.dev.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.woxitech.dev.dao.gen.WmAppMapper;
import cn.com.woxitech.dev.dao.gen.WmCatalogMapper;
import cn.com.woxitech.dev.dao.gen.WmCatalogRoomMapper;
import cn.com.woxitech.dev.dao.gen.WmCatalogUserMapper;
import cn.com.woxitech.dev.dao.gen.WmLecturePageMapper;
import cn.com.woxitech.dev.dao.gen.WmSettingMapper;
import cn.com.woxitech.dev.model.gen.WmApp;
import cn.com.woxitech.dev.model.gen.WmAppExample;
import cn.com.woxitech.dev.model.gen.WmCatalog;
import cn.com.woxitech.dev.model.gen.WmCatalogExample;
import cn.com.woxitech.dev.model.gen.WmCatalogRoomExample;
import cn.com.woxitech.dev.model.gen.WmCatalogRoomKey;
import cn.com.woxitech.dev.model.gen.WmCatalogUserExample;
import cn.com.woxitech.dev.model.gen.WmCatalogUserKey;
import cn.com.woxitech.dev.model.gen.WmLecturePage;
import cn.com.woxitech.dev.model.gen.WmLecturePageExample;
import cn.com.woxitech.dev.model.gen.WmSetting;
import cn.com.woxitech.dev.model.gen.WmSettingExample;

@Service
public class AppService {
	@Autowired
	WmAppMapper wmAppMapper;
	@Autowired
	WmSettingMapper wmSettingMapper;

	public WmApp getWmAppById(int id){
		
		return this.wmAppMapper.selectByPrimaryKey(id);
		
	}
	
	public String getSettingByKey(String key) {
		// TODO Auto-generated method stub

		WmSettingExample e = new WmSettingExample();
		e.createCriteria().andMkeyEqualTo(key);
		List<WmSetting> list = this.wmSettingMapper.selectByExample(e);
		if(list == null || list.isEmpty()){
			return "";
		}else{
			return list.get(0).getMval();
		}

	}
	
	public List<String> getOrguuidStrList() {
		// TODO Auto-generated method stub
		WmAppExample e = new WmAppExample();
		List<WmApp> list = this.wmAppMapper.selectByExample(e);
		
		List<String> strList = new ArrayList<String>();
		for(WmApp app : list){
			strList.add(app.getDefaultorguuid());
		}
		
		return strList;
	}

	public WmApp getDefaultWmApp() {
		// TODO Auto-generated method stub
		WmAppExample e = new WmAppExample();
		List<WmApp> list = this.wmAppMapper.selectByExample(e);
		
		if(list != null && !list.isEmpty()){
			return list.get(0);
		}else{
			return null;
		}
		
	}
}
